import 'package:flutter/material.dart';

import '../../../../model/ranktabitem.dart';

class LeftMenu extends StatefulWidget {
  LeftMenu({Key? key}) : super(key: key);

  @override
  State<LeftMenu> createState() => _LeftMenuState();
}

class _LeftMenuState extends State<LeftMenu> {
  List<TabItem> leftMenuList = [
    TabItem('1', title: '最热榜', isChecked: false),
    TabItem('2', title: '完结榜', isChecked: false),
    TabItem('3', title: '收藏榜', isChecked: false),
    TabItem('4', title: '推荐榜', isChecked: false),
    TabItem('5', title: '新书榜', isChecked: false),
    TabItem('6', title: '评分榜', isChecked: false),
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 70.0,
      child: ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return Container(
              height: 60.0,
              width: 70.0,
              decoration: BoxDecoration(
                  color: leftMenuList[index].isChecked!
                      ? Colors.grey.shade100
                      : Colors.white,
                  border: Border(
                      left: leftMenuList[index].isChecked!
                          ? BorderSide(width: 3.0, color: Colors.blue.shade500)
                          : BorderSide.none)),
              child: GestureDetector(
                  onTap: () {
                    setState(() {
                      leftMenuList = leftMenuList
                          .map((e) => (e == leftMenuList[index]
                              ? TabItem(e.classId,
                                  title: e.title, isChecked: !e.isChecked!)
                              : TabItem(e.classId,
                                  title: e.title, isChecked: false)))
                          .toList();
                    });
                  },
                  child: Center(
                      child: Text(leftMenuList[index].title!.toString(),
                          style: TextStyle(
                            color: leftMenuList[index].isChecked!
                                ? Colors.blue.shade500
                                : Colors.black,
                          )))));
        },
        itemCount: leftMenuList.length,
      ),
    );
  }
}
